<template>
    <div>

        <h1>登录</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>姓名</td>
                    <td><input type="text" v-model="data.name"></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="data.pwd"></td>
                </tr>
                <tr>
                    <td class="2">
                      <input type="button" value="登录" @click="login">
                    </td> 
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios' 
import { useRouter } from 'vue-router'
import {useUserStore} from '../../stores/login'

const user=useUserStore();
const router=useRouter();


const data=ref({
    name:"",
    pwd:"",
})
const login=()=>{

    user.login.name=data.value.name;
    axios.get("https://localhost:7094/api/House/LoginHouse",{params:data.value}).then(res=>{
        if(res.data.id>0)
       {
         alert("登录成功") 
         user.login.name=data.value.name
         router.push({path:"/"}) 
       }
       if(res.data.id==-1)
       {
         alert("用户名称不存在")
         return;
       }
      if(res.data.id==-2)
       {
         alert("密码错误")
         return;
       }
     
    })
}

</script>


<style scoped>

</style>